<template>
  <div class="index">
    <head-text titleText="栏目管理"></head-text>
    <div class="list-content">
       <div class="filter-area">
        <Search :searchData="searchData" :searchItem="searchItem"></Search>
      </div>
      <div class="table-title">
        <span></span>
        <h5>栏目列表</h5>
      </div>
      <custom-table
        :tableData="tableData"
        :tableListData="tableListData"
        :tableBtn="tableBtn"
        :currentData="currentData"
        @onPageChange="onPageChange"
        @onSizeChange="onSizeChange"
        @handleView="handleView"
        @handleViewDelete="handleViewDelete"
        @handleViewArea="handleViewArea"
      ></custom-table>
    </div>
    <dialog-com :dialogObj="dialogObj" @reflash="getList"></dialog-com>
  </div>
</template>

<script>
import customTable from "@c/table";
import headText from "@c/headText";
import dialogCom from "./dialogCom";
import Search from "@c/search";
import {
  REPTILEISCRAWL,
} from "@u/wordbook";
import { getDetailColumnListApi,getDeleteListApi } from "@s/api";
export default {
  name: "index",
  data() {
    return {
      nowPage: 1,
      limit: 10,
       searchItem: [],
      currentData: {},
        searchData: {
          /** 栏目名 */
          label: '',
          /** 主题名 */
          subjectName:'',
          /** 是否爬取 */
          isCrawl:''
      },
      dialogObj: {
        id: "",
        view: false,
        title: "",
        show: false,
        form: {}
      },
      tableData: []
    };
  },
  components: {
    headText,
    Search,
    dialogCom,
    customTable
  },
  created() {
    this.searchItem = [
      {
        type: "input",
        label: "栏目名：",
        prop: "label",
        placeholder: "请输入",
      },
      {
        type: "input",
        label: "主题名",
        prop: "subjectName",
        placeholder: "请输入",
      },
      {
        type: "select",
        label: "是否爬取：",
        prop: "isCrawl",
        placeholder: "请选择",
        selectList: [{id:0,value:'未爬取',id:1,value:'已爬取'}]
      },
    ];
    //  table表格
    this.tableListData = [
      { width: "50", label: "", type: "index" },
      { prop: "subjectName", width: "", label: "主题名称" },
      { prop: "label", width: "", label: "栏目名称" },
      { prop: "description", width: "", label: "栏目描述" },
      { prop: "isCrawl", width: "", label: "是否爬取",type:'wordbook' ,wordbookList:this.getReptileIsCrawl },
      { prop: "createTime", width: "150", label: "创建时间" },
      { label: "操作", type: "btn", width: "180", fixed: "right" }
    ];
    // 按钮
    this.tableBtn = [
      {
        name: "编辑",
        btnType: "primary",
        handleFn: "handleView"
      },
       {
        name: "删除",
        btnType: "primary",
        handleFn: "handleViewDelete"
      },
       {
        name: "爬取",
        btnType: "primary",
        isShowStatus:'isCrawl',
        type: "isShow",
        isShowValue: 0,
        handleFn: "handleViewArea"
      }
    ];
  },
  mounted() {
    this.getList();
  },
  methods: {
    onPageChange(val) {
      this.nowPage = val;
      this.getList();
    },
    onSizeChange(val) {
      this.nowPage = 1;
      this.limit = val;
      this.getList();
    },
    //获取栏目列表
    getList() {
      let json = JSON.parse(JSON.stringify(this.searchData));
      json.pageSize = this.limit
      json.pageNo =this.nowPage
      getDetailColumnListApi(json).then(res => {
        this.currentData.total = res.total;
        this.tableData = res.list;
      });
    },
       handleViewDelete(v) {
      this.$confirm("此操作将删除该栏目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        getDeleteListApi([v.id]).then(() => {
          this.getList();
          this.$message({
            type: "success",
            message: "删除成功！"
          });
        });
      });
    },
     // 搜索事件
    getDataList(val) {
      this.searchData = val;
      this.nowPage = 1;
      this.limit = 10;
      this.$nextTick(() => {
        this.getList();
      });
    },
    getReptileIsCrawl(val){
      return REPTILEISCRAWL[val]
    },
    handleView(v) {
      this.dialogObj.id = v.id;
      this.dialogObj.form = v;
      this.dialogObj.view = false; // 编辑
      this.dialogObj.title = "编辑栏目";
      this.dialogObj.show = true;
    },
     handleViewArea(v) {
      this.dialogObj.id = v.id;
      this.dialogObj.form = v;
      this.dialogObj.view = false; // 编辑
      this.dialogObj.title = "爬取栏目范围";
      this.dialogObj.show = true;
    }
  }
};
</script>
<style scoped lang="scss"></style>
